package com.zdxlz.fcmp.common.core.util;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

import java.io.IOException;

/**
 * @description：IP 解析工具类
 * @author：aman
 * @data 2025/3/17 14:17
 */
public class IPAPILocationUtil {
    public static void main(String[] args) {
        String apiKey = "351b8ae8bf567164b6172033e94bee4a";
        String ip = "183.192.168.1";
        String url = "https://restapi.amap.com/v3/ip?ip=" + ip + "&key=" + apiKey;
        try {
            String result = HttpUtil.doGet(url);
            JSONObject jsonObject = JSON.parseObject(result);
            String province = jsonObject.getString("province");
            String city = jsonObject.getString("city");
            System.out.println("result：" + result);
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
